$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'EvaluationTimeTeacher/Select',
        datatype: "json",
        colModel: [
             { label: '评价时间教师ID', name: 'evaluationTimeTeacherId', width: 40,key: true,hidden:true },
             { label: '评价时间ID', name: 'evaluationTimeId', width: 40 },
             { label: '可评教教师职工号', name: 'evaluationTeacherId', width: 40 },
             { label: '可评教教师名称', name: 'evaluationTeacherName', width: 40 },
             { label: '是否可评教', name: 'evaluable', width: 40 ,formatter: function(value, options, row){
                return value == 0 ?
                    '<span class="table-btn1 isNot">否</span>' :
                    '<span class="table-btn1 isSure">是</span>';
                    }},
         ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        postData:{
             "collegeName":vm.collageData
        },
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        collageData:null,
        collageValue:[],
        collageOptions:[],
        q:{
            key: null
        },
        showList: true,
        title: null,
        EvaluationTimeTeacher: {},
        evaluationTimeId: null
    },
    mounted(){
        $.ajax({
            url: baseURL + "/college/getAllcollege",
            data: {},
            success: function (r) {
                for (i = 0; i < r.list.length; i++) {
                    var tempJson={
                        'value':r.list[i].collegeName,
                        'label':r.list[i].collegeName
                    }
                    vm.collageOptions.push(tempJson)
                }
            }
        });
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function(){
            vm.showList = false;
            vm.title = "新增";
            vm.EvaluationTimeTeacher = {};
        },
        update: function () {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            $.get(baseURL + "EvaluationTimeTeacher/Info/"+id, function(r){
                vm.showList = false;
                vm.title = "修改";
                vm.EvaluationTimeTeacher = r.EvaluationTimeTeacher;
                vm.evaluationTimeId = r.EvaluationTimeTeacher.evaluationTimeId;
            });
        },
        del: function () {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "EvaluationTimeTeacher/Delete",
                    contentType: "application/json",
                    data: JSON.stringify(ids),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        saveOrUpdate: function () {
            if(vm.validator()){
                return ;
            }

            var url = vm.EvaluationTimeTeacher.evaluationTimeId == vm.evaluationTimeId ? "EvaluationTimeTeacher/Update" : "EvaluationTimeTeacher/Insert";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.EvaluationTimeTeacher),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        goString:function(data){
                var temp=""
                for(let i in data){
                    if(i==data.length-1){
                        temp+=('\''+data[i]+'\'')
                    }else{
                        temp+=('\''+data[i]+'\'')+','
                    }
                }
                return temp
            },
        reload: function () {
            vm.collageData=vm.goString(vm.collageValue);
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{
                "collegeName":vm.collageData,
                'evaluationTimeId': vm.q.key
                },
                page:page
            }).trigger("reloadGrid");
        },
        validator: function () {
            if(isBlank(vm.EvaluationTimeTeacher.evaluationTimeId)){
                alert("评价时间ID不能为空");
                return true;
            }
            if(isBlank(vm.EvaluationTimeTeacher.evaluationTeacherId)){
                alert("可评教教师职工号不能为空");
                return true;
            }
            if(isBlank(vm.EvaluationTimeTeacher.evaluationTeacherName)){
                alert("可评教教师名称不能为空");
                return true;
            }
            if(isBlank(vm.EvaluationTimeTeacher.evaluable)){
                alert("是否可评教不能为空");
                return true;
            }
            }
        }
});